package com.demo.grpc.controller;

import com.demo.grpc.entity.OrderDTO;
import com.demo.grpc.order.Order;
import com.demo.grpc.service.GrpcCartClientService;
import com.demo.grpc.service.GrpcClientService;
import com.demo.grpc.service.GrpcOrderClientService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class GrpcClientController {

    @Resource
    private GrpcClientService grpcClientService;

    @Resource
    private GrpcOrderClientService grpcOrderClientService;
    @Resource
    private GrpcCartClientService grpcCartClientService;


    @GetMapping("/hello")
    public String printMessage(@RequestParam(defaultValue = "Hanson") String name) {
        return grpcClientService.sendMessage(name);
    }

    @GetMapping("/order")
    public List<OrderDTO> printMessage2(@RequestParam(defaultValue = "Hanson") String name){
        return grpcOrderClientService.listOrders(name);
    }

    @GetMapping("/cart")
    public String printMessage(@RequestParam(defaultValue = "1") int count) {
        return grpcCartClientService.addToCart(count);
    }
}
